﻿using System.Collections.Generic;
using System.Linq;

using Sustainalytics.ESGRatings.Computing.Entities.ESG;
using Sustainalytics.ESGRatings.Computing.Entities;

namespace Sustainalytics.ESGRatings.DataContract.Mappers
{
    public static class FromDataContractMapper
    {
        public static ESGCompanyEntity ToDomainModel(this CompanyData input)
        {
            var result = new ESGCompanyEntity
            {
                Id = input.Id,
                IndustryGroup = input.IndustryGroup,
                PeerGroup = input.PeerGroup,
            };

            if (input.CompanyType.ToLowerInvariant() == "public")
            {
                result.Attributes |= ESGRatingsOptions.CompanyAttributesEnum.Public;
            }
            if (input.CompanyType.ToLowerInvariant() == "private")
            {
                result.Attributes |= ESGRatingsOptions.CompanyAttributesEnum.Private;
            }
            if (input.TemplateType == "Type A")
            {
                result.Attributes |= ESGRatingsOptions.CompanyAttributesEnum.TypeA;
            }
            if (input.TemplateType == "Type B")
            {
                result.Attributes |= ESGRatingsOptions.CompanyAttributesEnum.TypeB;
            }

            return result;
        }

        public static IEnumerable<ESGCompanyEntity> ToDomainModel(this IEnumerable<CompanyData> list)
        {
            return list.Select(item => item.ToDomainModel());
        }

        public static GovernanceCompanyEntity ToDomainModel(this Computing.Entities.Governance.CompanyData input)
        {
            var result = new GovernanceCompanyEntity(input.Id, input.PeerGroup, input.Region);

            return result;
        }

        public static ICollection<GovernanceCompanyEntity> ToDomainModel(this ICollection<Computing.Entities.Governance.CompanyData> list)
        {
            return list.Select(item => item.ToDomainModel()).ToList();
        }
    }
}